import type { App } from "vue";
import { useUserInfoStore } from "@/stores/userInfo";

const registerPermissionDirective = (app: App) => {
  app.directive("permission", (el, binding) => {
    // `mounted` 和 `updated` 时都调用
    // el 绑定指令的DOM元素
    // binding 指令信息对象（包含指令名称，指令值）
    const userInfoStore = useUserInfoStore();
    if (!userInfoStore.buttons.includes(binding.value)) {
      el.remove();
    }
  });
};

export default registerPermissionDirective;
